<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div {
        border: 3px solid;
        padding: 10px;
      }
    </style>
  </head>
  <body>
    <div id="box1">
      box1
      <div id="box2">
        box2
        <div id="box3">
          box3
          <div id="box4">box4</div>
        </div>
      </div>
    </div>
    <script>
      /*
        如何判断事件函数是否是点击自己触发的？
        1. 在所有事件对象中都能获取事件点击的目标对象 target
        2. 在所有事件函数中也都能获取到事件绑定对象 this
        3. 如果this和target相等说明点击就是自己
      */
      const box1 = document.getElementById("box1");
      const box2 = document.getElementById("box2");
      const box3 = document.getElementById("box3");
      const box4 = document.getElementById("box4");

      box1.onclick = function (e) {
        // target 点击目标元素对象
        console.log(e.target === this);
        console.log(1);
      };
      box2.onclick = function (e) {
        console.log(e.target === this);
        console.log(2);
      };
      box3.onclick = function (e) {
        console.log(e.target === this);
        console.log(3);
      };
      box4.onclick = function (e) {
        console.log(e.target === this);

        console.log(4);
      };
    </script>
  </body>
</html>
